package webmarket.model;

import java.io.Serializable;
import java.sql.Timestamp;

import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQuery;
import javax.persistence.Table;

import webmarket.common.ShopcategoryController;

/**
 * The persistent class for the merchandise database table.
 * 
 */
@Entity
@Table(name = "merchandise")
@NamedQuery(name = "Merchandise.findAll", query = "SELECT m FROM Merchandise m")
public class Merchandise implements Serializable {
	private static final long serialVersionUID = 1L;

	@Id
	private int id;

	private int categoryId;

	private Timestamp created;

	private String description;

	private Timestamp lastchange;

	private String name;

	private int price;

	//bi-directional many-to-one association to User
	@ManyToOne
	@JoinColumn(name = "userid")
	private User user;

	public Merchandise() {
	}

	public int getId() {
		return this.id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public Timestamp getCreated() {
		return this.created;
	}

	public void setCreated(Timestamp created) {
		this.created = created;
	}

	public String getDescription() {
		return this.description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public Timestamp getLastchange() {
		return this.lastchange;
	}

	public void setLastchange(Timestamp lastchange) {
		this.lastchange = lastchange;
	}

	public String getName() {
		return this.name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public int getPrice() {
		return this.price;
	}

	public void setPrice(int price) {
		this.price = price;
	}

	public User getUser() {
		return this.user;
	}

	public void setUser(User user) {
		this.user = user;
	}

	/**
	 * @return the categoryId
	 */
	public int getCategoryId() {
		return categoryId;
	}

	/**
	 * @param categoryId
	 *            the categoryId to set
	 */
	public void setCategoryId(int categoryId) {
		this.categoryId = categoryId;
	}

	public Shopcategory getCategory() {
		return ShopcategoryController.get(getCategoryId());
	}

	public void setCategory(Shopcategory category) {
		setCategoryId(category.getId());
	}

}